import pymysql;

'''
pymysql 工具模块
'''


# 获取mysql连接对象、游标对象
def get_connection_cursor():
    connection = pymysql.connect(host="127.0.0.1", port=3306, database="sg",
                                 user="root", password="1216018662", charset="utf8");
    cursor = connection.cursor();
    return connection, cursor;


# 执行增删改操作
def execute_(sql, cursor):
    return cursor.execute(sql);


# 执行查询操作
def query_(sql, cursor):
    cursor.execute(sql);
    return cursor.fetchall();


# 提交事务
def commit_(connection):
    connection.commit();


# 回滚事务
def rollback_(connection):
    if connection:
        connection.rollback();


# 关闭连接
def close_(connection, cursor):
    if connection:
        connection.close();
    if cursor:
        cursor.close();
